import csv
from util.log import logger
class CsvUtil:
    def __init__(self,file):
        self.file = file

    # 读取csv数据 返回字典格式 字典键为第一行
    def getCsvData(self):
        f = open(file=self.file,mode='r',encoding='utf-8-sig')
        read = list(csv.reader(f)) #读取的数据
        dictList = []
        for i in range(1,len(read)): # 从第二行开始读取数据
            dict = {}
            data = read[i]
            keys = read[0]
            for j in range(len(keys)):
                dict[keys[j]] = data[j]
            dictList.append(dict)

        logger.info('读取csv格式化后内容:'+str(dictList))
        return dictList
